<template>
    <nav role="navigation" class="navbar navbar-fixed-top">
        <div class="container header">
            <div class="navbar-header">
                <button type="button" data-toggle="collapse" data-target="#menu" class="navbar-toggle" aria-expanded="false">
                    <span class="sr-only">展开导航</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a href="/" class="navbar-brand">
                    <div>
                        <img src="../assets/logo_b.png" alt="隽酒" title="隽酒">
                        <span class="dot">· </span>
                        <span>会说话的酒</span>
                    </div>
                </a>
            </div>
            <div id="menu" class="collapse navbar-collapse" aria-expanded="false">
                <ul class="nav navbar-nav navbar-right">
                    <li v-for="(item, index) in catetory_lists" :key="index">
                        <a :href="`/${item.dirname}`" :class="{'active': current_path.indexOf(item.dirname) > -1}">{{item.name}}</a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>
</template>
<script>
import { getCategory } from '@/api'
export default {
    data() {
        return {
            catetory_lists: []
        }
    },
    computed: {
        current_path() {
            return this.$route.path
        }
    },
    methods: {
        init() {
            getCategory().then(res => {
                if (res.code == 1) {
                    this.catetory_lists = res.data
                }
            })
        }
    },
    created() {
        this.init()
    }
}
</script>
